package com.uls.zsw.service.impl;

import java.util.List;
import com.uls.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.uls.zsw.mapper.ElectricityManageMapper;
import com.uls.zsw.domain.ElectricityManage;
import com.uls.zsw.service.IElectricityManageService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 电源管理Service业务层处理
 * 
 * @author zsw
 * @date 2024-11-20
 */
@Service
public class ElectricityManageServiceImpl implements IElectricityManageService 
{
    @Autowired
    private ElectricityManageMapper electricityManageMapper;

    /**
     * 查询电源管理
     * 
     * @param electricityId 电源管理主键
     * @return 电源管理
     */
    @Transactional
    @Override
    public ElectricityManage selectElectricityManageByElectricityId(Long electricityId)
    {
        ElectricityManage electricityManage=electricityManageMapper.selectElectricityManageByElectricityId(electricityId);
        String dn=electricityManageMapper.getDNByDI(electricityManage.getDormitoryId());
        electricityManage.setSelecteddn(dn);
        return electricityManage;
    }

    /**
     * 查询电源管理列表
     * 
     * @param electricityManage 电源管理
     * @return 电源管理
     */
    @Transactional
    @Override
    public List<ElectricityManage> selectElectricityManageList(ElectricityManage electricityManage)
    {
        if(electricityManage!=null){
            Long di=electricityManageMapper.getDIByDN(electricityManage.getSelecteddn());
            electricityManage.setDormitoryId(di);
        };
        List<ElectricityManage> electricityManageList=electricityManageMapper.selectElectricityManageList(electricityManage);
        for(ElectricityManage electricityManage1:electricityManageList){
            String dn=electricityManageMapper.getDNByDI(electricityManage1.getDormitoryId());
            electricityManage1.setSelecteddn(dn);
        }
        return electricityManageList;
    }

    /**
     * 新增电源管理
     * 
     * @param electricityManage 电源管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertElectricityManage(ElectricityManage electricityManage)
    {
        electricityManage.setCreateTime(DateUtils.getNowDate());
        System.out.println(electricityManage);
        Long di=electricityManageMapper.getDIByDN(electricityManage.getSelecteddn());
        electricityManage.setDormitoryId(di);
        System.out.println(electricityManage);
        return electricityManageMapper.insertElectricityManage(electricityManage);
    }

    /**
     * 修改电源管理
     * 
     * @param electricityManage 电源管理
     * @return 结果
     */
    @Transactional
    @Override
    public int updateElectricityManage(ElectricityManage electricityManage)
    {
        Long di=electricityManageMapper.getDIByDN(electricityManage.getSelecteddn());
        electricityManage.setDormitoryId(di);
        return electricityManageMapper.updateElectricityManage(electricityManage);
    }

    /**
     * 批量删除电源管理
     * 
     * @param electricityIds 需要删除的电源管理主键
     * @return 结果
     */
    @Override
    public int deleteElectricityManageByElectricityIds(Long[] electricityIds)
    {
        return electricityManageMapper.deleteElectricityManageByElectricityIds(electricityIds);
    }

    /**
     * 删除电源管理信息
     * 
     * @param electricityId 电源管理主键
     * @return 结果
     */
    @Override
    public int deleteElectricityManageByElectricityId(Long electricityId)
    {
        return electricityManageMapper.deleteElectricityManageByElectricityId(electricityId);
    }

    @Override
    public ElectricityManage selectByDormitoryId(Long dormitoryId) {
        return electricityManageMapper.selectByDormitoryId(dormitoryId);
    }

    @Override
    public Long getDIByDN(String DN) {
        return electricityManageMapper.getDIByDN(DN);
    }

    @Override
    public String getDNByDI(Long DI) {
        return electricityManageMapper.getDNByDI(DI);
    }
}
